home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_200
/
298_01
/
curses.h
< prev
next >
Wrap
C/C++ Source or Header
|
1988-07-23
|
16KB
|
456 lines
/* PC Curses. (C) Copyright 1987 Jeffrey S. Dean. All Rights Reserved. */
/* curses.h -- include file for PC Curses */
#ifndef PC_CURSES
/* PC_CURSES is used to identify this particular package;
* also ensures that this file is processed only once.
*/
#define PC_CURSES
#include <stdio.h>
/* version information */
extern char *_pc_curses;
/* characters in PC Curses are always of type CHTYPE
* in the current implementation, the upper byte is
* used to store attribute information.
*/
#define CHTYPE short
/* the basic window structure */
typedef struct _win {
CHTYPE **txt; /* text, as an array of line ptrs */
short cury, curx; /* current x and y coordinates */
short ox, oy; /* x and y origin */
short lines, cols; /* size of full screen */
short mfy, mfx, mly, mlx; /* area to be refreshed */
CHTYPE attrs; /* screen attributes */
short flags; /* miscellaneous information */
short scrtop, scrbot; /* scrolling region boundaries */
CHTYPE *base; /* base address of character map */
} WINDOW;
#define A_ATTRIBUTES 0xff00
#define A_CHARTEXT 0x00ff
/* Support is provided for both monochrome and color displays,
* by providing a set of attributes that can be used with
* the "attr" functions.
*
* The meaning of the attributes depends on the display used.
* Note that the meanings may not translate well: for example,
* "underline" on a color display appears as blue text on a
* black background.
*/
/* Although an attrbiute of zero means "invisible" on a PC, this package
* has been hacked (for compatibility) so that zero also means "normal".
*/
#define A_NONE 0
#define A_NORMAL 0x0700
/* On a PC, if !(attributes & A_VISIBLE), character will be invisible */
#define A_VISIBLE 0x7700
/* screen attributes for (monochrome) IBM PC
* Note that not all combinations are meaningful;
* see a PC reference manual for more info.
*/
#define A_REVERSE 0x7000
#define A_UNDERLINE 0x0100
#define A_BOLD 0x0800
#define A_BLINK 0x8000
#define A_STANDOUT A_REVERSE
#define A_DIM A_NONE
/* color attributes
* use the A_COLOR macro to specify foreground and background colors.
* For example, to set the stdscr to use green characters on a yellow
* background, you would say:
* attrset( A_COLOR(A_GREEN, A_YELLOW) );
*/
#define A_COLOR(fore,back) ( (fore) << 8 | (back) <<12 )
/* primary colors */
#define A_BLACK 0
#define A_BLUE 1
#define A_GREEN 2
#define A_RED 4
/* secondary colors (combinations of primary colors) */
#define A_CYAN 3 /* blue-green */
#define A_MAGENTA 5 /* purple */
#define A_BROWN 6 /* (or dark yellow) */
#define A_WHITE 7 /* white (or light gray) */
/* the "intensity" bit
* Warning: If used on the background color, the intensity bit
* will cause the text to blink. This reduces the number of
* background colors from 16 to 8. (There is a hardware-dependent
* method around this problem, but PC Curses does not support it.)
*/
#define A_INTENSE 8
/* "light" colors */
#define A_GRAY (A_INTENSE|A_BLACK)
#define A_LBLUE (A_INTENSE|A_BLUE)
#define A_LGREEN (A_INTENSE|A_GREEN)
#define A_LCYAN (A_INTENSE|A_CYAN)
#define A_LRED (A_INTENSE|A_RED)
#define A_LMAGENTA (A_INTENSE|A_MAGENTA)
#define A_YELLOW (A_INTENSE|A_BROWN)
#define A_BRIGHTWHITE (A_INTENSE|A_WHITE)
/* Unix Sys V.3 extended character set
*
* Note: this is an approximation of the V.3 approach,
* which requires that all line graphics characters have the
* bit A_ALTCHARSET turned on (if it is off, it means that
* the terminal does not support that particular character).
* Since PC Curses provides color support (see above), there are
* no extra bits available for A_ALTCHARSET. As an approximation,
* A_ALTCHARSET is defined as 0x80. Since many of the PC graphics
* characters have this bit set, this approximation works most of
* the time. However, some graphics characters fall in the range
* 0x00 to 0x1F, which means that testing for A_ALTCHARSET will
* fail.
*/
#define A_ALTCHARSET 0x0080
#define ACS_ULCORNER 218
#define ACS_LLCORNER 192
#define ACS_URCORNER 191
#define ACS_LRCORNER 217
#define ACS_RTEE 180
#define ACS_LTEE 195
#define ACS_BTEE 193
#define ACS_TTEE 194
#define ACS_HLINE 196
#define ACS_VLINE 179
#define ACS_PLUS '+'
#define ACS_DIAMOND 4
#define ACS_CKBOARD 176
#define ACS_DEGREE 248
#define ACS_PLMINUS 241
#define ACS_BULLET 249
#define ACS_LARROW 27
#define ACS_RARROW 26
#define ACS_DARROW 25
#define ACS_UARROW 24
#define ACS_BOARD '#'
#define ACS_LANTERN '#'
/* "double line" characters (not defined by SysV.3) */
#define ACS_DULCORNER 201
#define ACS_DLLCORNER 100
#define ACS_DURCORNER 187
#define ACS_DLRCORNER 188
#define ACS_DRTEE 185
#define ACS_DLTEE 204
#define ACS_DBTEE 202
#define ACS_DTTEE 203
#define ACS_DHLINE 205
#define ACS_DVLINE 186
/* Curses provides getyx() to return current coordinates; newer versions
* of curses also provide getbegyx() and getmaxyx() to return beginning
* and ending coordinates. The coordinate accessing macros below are
* non-standard, but they allow just a single coordinate to be accessed.
* This saves the trouble of declaring an unneeded variable, eliminates
* an unneeded assignment, and prevents the compiler (or lint) from
* complaining about a variable that is set but never used.
*/
#define BEGY(w) w->oy /* starting position of window */
#define BEGX(w) w->ox
#define CURY(w) w->cury /* current position in window */
#define CURX(w) w->curx
#define MAXY(w) w->lines /* number of lines */
#define MAXX(w) w->cols /* number of columns */
#define WGETC(w,y,x) w->txt[y][x] /* get character from window */
#define WPUTC(w,y,x,c) w->txt[y][x]=c /* place character in window */
/* for win->flags */
/* #define W_WRAPOK 0x1 /* ok for lines to wrap around */
#define W_CLEAROK 0x2 /* ok to clear window */
#define W_MODIFIED 0x4 /* window has been modified */
#define W_SCROLLOK 0x8 /* ok to scroll window */
#define W_KEYPAD 0x10 /* use keypad translations */
#define W_NODELAY 0x20 /* non-blocking tty input */
#define W_TOUCHED 0x40 /* window has been touched */
#define W_SUBWIN 0x80 /* window is a sub-window */
#define W_LEAVEOK 0x100 /* ignore cursor */
#define W_META 0x200 /* enable meta mode */
#define W_PAD 0x400 /* window is really a pad */
#define W_PADNOCUR 0x800 /* internal pad cursor control */
#define W_FULLWIN 0x1000 /* window is full screen */
/* macros to set/clear win->flags */
#define scrollok(win,flag) _winflag(win,flag,W_SCROLLOK)
#define nodelay(win,flag) _winflag(win,flag,W_NODELAY)
#define leaveok(win,flag) _winflag(win,flag,W_LEAVEOK)
#ifndef SIMPGETCH
#define keypad(win,flag) _winflag(win,flag,W_KEYPAD)
#define meta(win,flag) _winflag(win,flag,W_META)
#endif
#define clearok(win,flag) \
( (win)->flags & W_FULLWIN ? _winflag(win, flag, W_CLEAROK) : ERR )
/* standard stuff for curses */
#define TRUE 1
#define FALSE 0
#define ERR 0
#define OK 1
/* standard curses variables */
extern int LINES, COLS; /* size of full screen */
extern WINDOW *stdscr, *curscr; /* current and standard screens */
/* for tty input emulation mode */
extern int _ttyflags;
#define T_RAW 01
#define T_CRMOD 02
#define T_ECHO 04
#define T_NONL 010
/* settings for screen update method; this is still experimental */
#define T_BIOS 0 /* use bios updating */
#define T_DIRECT -1 /* direct update, figure out type */
#define T_MA 0xb000 /* direct update, assume monochrome */
#define T_CGA 0xb800 /* direct update, assume cga */
#define T_EGA 0xa800 /* direct update, assume ega ?? */
/* PC line drawing characters (horizontal/vertical pairs) */
#define S_HOR 196 /* single line */
#define S_VERT 179
#define D_HOR 205 /* double line */
#define D_VERT 186
#define T_HOR 220 /* thick solid line, not quite perfect */
#define T_VERT 219
WINDOW *initscr(), *newwin(), *subwin(), *newpad();
WINDOW *shadowwin();
char *unctrl();
#define getyx(win,y,x) (y = CURY(win), x = CURX(win))
#define getbegy